//
//  ByConjurationSuccessVC.m
//  mijifen_ios
//
//  Created by mc on 2017/10/26.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByConjurationSuccessVC.h"

// view
#import "ByViewHeaderSuccess.h"         // 成功视图

@interface ByConjurationSuccessVC ()

@end

@implementation ByConjurationSuccessVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"发放成功";
    [self addLeftBackBarButtonItem];
    self.view.backgroundColor = BY_TABLE_COLOR;
    [self createViews];
}

#pragma mark - 创建视图
- (void)createViews{
    ByViewHeaderSuccess *headerView = [[ByViewHeaderSuccess alloc] initWith:@"StoreCollection_paysuccess" title:@"发放成功"];
    [self.view addSubview:headerView];
    __block CGFloat height;
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0,*)) {
            height = (self.view.height - 50 * 2 - 10 - self.view.safeAreaInsets.bottom) / 2;
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, height));
        }else{
            height = (self.view.height - 50 * 2 - 10) / 2;
            make.top.equalTo(self.view.mas_top);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, height));
        }
        
    }];
    
    // 返回首页
    UIButton *backButton = [[UIButton alloc] init];
    [self.view addSubview:backButton];
    [backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0,*)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        }else{
            make.bottom.equalTo(self.view.mas_bottom);
        }
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 50));
    }];
    [backButton setBackgroundColor:BY_THEME_COLOR];
    [backButton setTitle:@"返回首页" forState:UIControlStateNormal];
    [backButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
    
    // 继续发放
    UIButton *continueButton = [[UIButton alloc] init];
    [self.view addSubview:continueButton];
    [continueButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(backButton.mas_top).offset(- 10);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 50));
    }];
    [continueButton setBackgroundColor:BY_TEXT_COLOR];
    [continueButton setTitle:@"继续发放" forState:UIControlStateNormal];
    [continueButton setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
    
    [continueButton addTarget:self action:@selector(continueAction:) forControlEvents:UIControlEventTouchUpInside];
    [backButton addTarget:self action:@selector(backtoIndex:) forControlEvents:UIControlEventTouchUpInside];
    
    
    // 恭喜
    UILabel *gongxiLabel = [[UILabel alloc] init];
    [self.view addSubview:gongxiLabel];
    [gongxiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headerView.mas_bottom).offset(25);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 40));
    }];
    gongxiLabel.textAlignment = NSTextAlignmentCenter;
    gongxiLabel.textColor = [UIColor colorWithR:224 g:141 b:42];
    gongxiLabel.font = B_FONT(40);
    gongxiLabel.text = @"恭喜";
    
    // 发放的信息
    UILabel *infoLabel = [[UILabel alloc] init];
    [self.view addSubview:infoLabel];
    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(gongxiLabel.mas_bottom).offset(25);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 30));
    }];
    infoLabel.font = FONT(18);
    infoLabel.textAlignment = NSTextAlignmentCenter;
    
    // alert
    UILabel *alertLabel = [[UILabel alloc] init];
    alertLabel.numberOfLines = 0;
    [self.view addSubview:alertLabel];
    [alertLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(infoLabel.mas_bottom).offset(25);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(infoLabel.mas_bottom).offset(15);
        make.bottom.equalTo(continueButton.mas_top).offset(-10);
    }];
    alertLabel.textAlignment = NSTextAlignmentCenter;
    NSArray *alertArray = @[@"席卷整个平台所有会员，\n只要你敢付出，就一定有收货！",@"针对特定会员，刺激回头客，客户永不丢失！"];
    alertLabel.text = alertArray[self.type];
    alertLabel.textColor = [UIColor lightGrayColor];
    alertLabel.textAlignment = NSTextAlignmentCenter;
    alertLabel.font = FONT(16);
    alertLabel.adjustsFontSizeToFitWidth = YES;
    
    
    
    // 测试数据
//    infoLabel.text = @"您发放了 50个 5元红包！";
    infoLabel.text = [NSString stringWithFormat:@"您发放了%@个 %@元红包！",self.redCount,self.price];
    

}

#pragma mark - 点击事件
// 继续发放
- (void)continueAction:(UIButton *)button{
    [self dismissViewControllerAnimated:YES completion:nil];
}

// 返回首页
- (void)backtoIndex:(UIButton *)button{
//    UIWindow *window = [UIApplication sharedApplication].keyWindow;
//    window.rootViewController = [[ByTabBrController alloc] init];
//    [self dismissViewControllerAnimated:YES completion:nil];
//    ByTabBrController *tabBar = [ByTabBrController shareSigleton];
//    tabBar.selectedButtonIndex = 0;

}


@end
